<template>
  <div class="article-page">
    <a-page-header title="资讯管理" sub-title="发布和管理平台资讯" />
    
    <a-card class="card-shadow">
      <template #extra>
        <a-button type="primary" @click="showModal = true">
          <template #icon><plus-outlined /></template>
          发布资讯
        </a-button>
      </template>
      
      <a-table
        :columns="columns"
        :data-source="dataSource"
        :loading="loading"
      >
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'cover'">
            <a-image :src="record.coverUrl" width="80" />
          </template>
          
          <template v-else-if="column.key === 'status'">
            <a-tag :color="record.status === 'PUBLISHED' ? 'green' : 'orange'">
              {{ record.status === 'PUBLISHED' ? '已发布' : '草稿' }}
            </a-tag>
          </template>
          
          <template v-else-if="column.key === 'action'">
            <a-space>
              <a-button type="link" size="small">编辑</a-button>
              <a-button type="link" size="small">删除</a-button>
            </a-space>
          </template>
        </template>
      </a-table>
    </a-card>
    
    <!-- 发布资讯弹窗 -->
    <a-modal
      v-model:open="showModal"
      title="发布资讯"
      width="800px"
      @ok="handleSubmit"
    >
      <a-form :model="formData" :label-col="{ span: 4 }">
        <a-form-item label="标题">
          <a-input v-model:value="formData.title" />
        </a-form-item>
        
        <a-form-item label="分类">
          <a-select v-model:value="formData.categoryId">
            <a-select-option :value="1">教育资讯</a-select-option>
            <a-select-option :value="2">学习方法</a-select-option>
          </a-select>
        </a-form-item>
        
        <a-form-item label="内容">
          <a-textarea v-model:value="formData.content" :rows="8" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { PlusOutlined } from '@ant-design/icons-vue'

const loading = ref(false)
const showModal = ref(false)

const columns = [
  { title: '封面', key: 'cover', width: 100 },
  { title: '标题', dataIndex: 'title', key: 'title' },
  { title: '分类', dataIndex: 'category', key: 'category' },
  { title: '浏览量', dataIndex: 'views', key: 'views' },
  { title: '发布时间', dataIndex: 'publishedAt', key: 'publishedAt' },
  { title: '状态', key: 'status' },
  { title: '操作', key: 'action', width: 150 }
]

const dataSource = ref([
  {
    id: 1,
    title: '如何提高学习效率',
    coverUrl: 'https://via.placeholder.com/300x200',
    category: '学习方法',
    views: 1250,
    publishedAt: '2024-01-15',
    status: 'PUBLISHED'
  }
])

const formData = reactive({
  title: '',
  categoryId: null,
  content: ''
})

const handleSubmit = () => {
  showModal.value = false
}
</script>

